package logic

import (
	"ck/models/mysql"
	"context"
	"gorm.io/gorm"

	"ck/ckrpc/ckrpc"
	"ck/ckrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopUpdateLogic {
	return &ShopUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopUpdateLogic) ShopUpdate(in *ckrpc.ShopUpdateRequest) (*ckrpc.ShopUpdateResponse, error) {
	// todo: add your logic here and delete this line

	shop := mysql.Shop{
		Model:    gorm.Model{ID: uint(in.ShopId)},
		ShopName: in.ShopName,
		Address:  in.Address,
		UserId:   int(in.UserId),
	}
	mysql.DB.Debug().Updates(&shop)

	return &ckrpc.ShopUpdateResponse{
		ShopId: int64(shop.ID),
	}, nil
}
